/**
 * 松散序列
 */
#include <atomic>
#include <thread>
#include <iostream>

std::atomic<bool> x, y;
std::atomic<int> z;

void write_x_then_y() {
    // 这里顺序不一致
    x.store(true, std::memory_order_relaxed);
    y.store(true, std::memory_order_relaxed);
}

void read_y_then_x() {
    while (!y.load(std::memory_order_relaxed));
    // 可能为false
    if (x.load(std::memory_order_relaxed)) {
        ++z;
    }
}

int main(int argc, char const *argv[])
{
    x = false;
    y = false;
    z = 0;

    std::thread a(write_x_then_y);
    std::thread b(read_y_then_x);

    a.join();
    b.join();

    std::cout << z.load() << std::endl;
    
    return 0;
}
